<!DOCTYPE html>
<html style="display: none;" lang="zh">
    <head>
    <meta charset="utf-8">
    <!--
        © Material Theme
        https://github.com/viosey/hexo-theme-material
        Version: 1.4.0 -->
    <script>window.materialVersion = "1.4.0"</script>

    <!-- Title -->
    
    <title>
        
            Ubuntu 服务器的安装配置 | 
        
        David&#39;s blog
    </title>

    <!-- dns prefetch -->
    <meta http-equiv="x-dns-prefetch-control" content="on">
    
    
    
    
    
    
    
    
    
    

    <!-- Meta & Info -->
    <meta http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="theme-color" content="#0097A7">
    <meta name="author" content="David">
    <meta name="description" itemprop="description" content="">
    <meta name="keywords" content="">

    <!-- Site Verification -->
    
    

    <!-- Favicons -->
    <link rel="icon shortcut" type="image/ico" href="/img/favicon.png">
    <link rel="icon" sizes="192x192" href="/img/favicon.png">
    <link rel="apple-touch-icon" href="/img/favicon.png">

    <!--iOS -->
    <meta name="apple-mobile-web-app-title" content="Title">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="480">

    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">

    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="David&#39;s blog">

    <!-- The Open Graph protocol -->
    <meta property="og:url" content="http://yoursite.com/blog">
    <meta property="og:type" content="blog">
    <meta property="og:title" content="Ubuntu 服务器的安装配置 | David&#39;s blog">
    <meta property="og:image" content="/img/favicon.png" />
    <meta property="og:description" content="">
    

    
        <meta property="article:published_time" content="8月 18, 2017" />
        <meta property="article:modified_time" content="8月 18, 2017" />
    

    <!-- The Twitter Card protocol -->
    <meta name="twitter:title" content="Ubuntu 服务器的安装配置 | David&#39;s blog">
    <meta name="twitter:description" content="">
    <meta name="twitter:image" content="/img/favicon.png">
    <meta name="twitter:card" content="summary_large_image" />
    <meta name="twitter:url" content="http://yoursite.com/blog" />

    <!-- Add canonical link for SEO -->
    
        <link rel="canonical" href="http://yoursite.com/blog/blog/2017/08/18/server-setup/index.html" />
    

    <!-- Structured-data for SEO -->
    
        


<script type="application/ld+json">
{
    "@context": "https://schema.org",
    "@type": "Article",
    "publisher": {
        "@type": "Organization",
        "name": "David&#39;s blog",
        "logo": "/img/favicon.png"
    },
    "author": {
        "@type": "Person",
        "name": "David",
        "image": {
            "@type": "ImageObject",
            "url": "/img/favicon.png"
        },
        "description": "Hi, nice to meet you"
    },
    "headline": "Ubuntu 服务器的安装配置",
    "url": "http://yoursite.com/blog/blog/2017/08/18/server-setup/index.html",
    "datePublished": "8月 18, 2017",
    "dateModified": "8月 18, 2017",
    "description": "",
    "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": "http://yoursite.com/blog"
    }
}
</script>


    

    <!--[if lte IE 9]>
        <link rel="stylesheet" href="/css/ie-blocker.css">

        
            <script src="/js/ie-blocker.zhCN.js"></script>
        
    <![endif]-->

    <!-- Import lsloader -->
    <script>(function(){window.lsloader={jsRunSequence:[],jsnamemap:{},cssnamemap:{}};lsloader.removeLS=function(key){try{localStorage.removeItem(key)}catch(e){}};lsloader.setLS=function(key,val){try{localStorage.setItem(key,val)}catch(e){}};lsloader.getLS=function(key){var val="";try{val=localStorage.getItem(key)}catch(e){val=""}return val};versionString="/*"+materialVersion+"*/";lsloader.clean=function(){try{var keys=[];for(var i=0;i<localStorage.length;i++){keys.push(localStorage.key(i))}keys.forEach(function(key){var data=lsloader.getLS(key);if(data&&data.indexOf(versionString)===-1){lsloader.removeLS(key)}})}catch(e){}};lsloader.clean();lsloader.load=function(jsname,jspath,cssonload){cssonload=cssonload||function(){};var code;code=this.getLS(jsname);if(code&&code.indexOf(versionString)===-1){this.removeLS(jsname);this.requestResource(jsname,jspath,cssonload);return}if(code){var versionNumber=code.split(versionString)[0];if(versionNumber!=jspath){console.log("reload:"+jspath);this.removeLS(jsname);this.requestResource(jsname,jspath,cssonload);return}code=code.split(versionString)[1];if(/\.js?.+$/.test(versionNumber)){this.jsRunSequence.push({name:jsname,code:code});this.runjs(jspath,jsname,code)}else{document.getElementById(jsname).appendChild(document.createTextNode(code));cssonload()}}else{this.requestResource(jsname,jspath,cssonload)}};lsloader.requestResource=function(name,path,cssonload){var that=this;if(/\.js?.+$/.test(path)){this.iojs(path,name,function(path,name,code){that.setLS(name,path+versionString+code);that.runjs(path,name,code)})}else if(/\.css?.+$/.test(path)){this.iocss(path,name,function(code){document.getElementById(name).appendChild(document.createTextNode(code));that.setLS(name,path+versionString+code)},cssonload)}};lsloader.iojs=function(path,jsname,callback){var that=this;that.jsRunSequence.push({name:jsname,code:""});try{var xhr=new XMLHttpRequest;xhr.open("get",path,true);xhr.onreadystatechange=function(){if(xhr.readyState==4){if(xhr.status>=200&&xhr.status<300||xhr.status==304){if(xhr.response!=""){callback(path,jsname,xhr.response);return}}that.jsfallback(path,jsname)}};xhr.send(null)}catch(e){that.jsfallback(path,jsname)}};lsloader.iocss=function(path,jsname,callback,cssonload){var that=this;try{var xhr=new XMLHttpRequest;xhr.open("get",path,true);xhr.onreadystatechange=function(){if(xhr.readyState==4){if(xhr.status>=200&&xhr.status<300||xhr.status==304){if(xhr.response!=""){callback(xhr.response);cssonload();return}}that.cssfallback(path,jsname,cssonload)}};xhr.send(null)}catch(e){that.cssfallback(path,jsname,cssonload)}};lsloader.iofonts=function(path,jsname,callback,cssonload){var that=this;try{var xhr=new XMLHttpRequest;xhr.open("get",path,true);xhr.onreadystatechange=function(){if(xhr.readyState==4){if(xhr.status>=200&&xhr.status<300||xhr.status==304){if(xhr.response!=""){callback(xhr.response);cssonload();return}}that.cssfallback(path,jsname,cssonload)}};xhr.send(null)}catch(e){that.cssfallback(path,jsname,cssonload)}};lsloader.runjs=function(path,name,code){if(!!name&&!!code){for(var k in this.jsRunSequence){if(this.jsRunSequence[k].name==name){this.jsRunSequence[k].code=code}}}if(!!this.jsRunSequence[0]&&!!this.jsRunSequence[0].code&&this.jsRunSequence[0].status!="failed"){var script=document.createElement("script");script.appendChild(document.createTextNode(this.jsRunSequence[0].code));script.type="text/javascript";document.getElementsByTagName("head")[0].appendChild(script);this.jsRunSequence.shift();if(this.jsRunSequence.length>0){this.runjs()}}else if(!!this.jsRunSequence[0]&&this.jsRunSequence[0].status=="failed"){var that=this;var script=document.createElement("script");script.src=this.jsRunSequence[0].path;script.type="text/javascript";this.jsRunSequence[0].status="loading";script.onload=function(){that.jsRunSequence.shift();if(that.jsRunSequence.length>0){that.runjs()}};document.body.appendChild(script)}};lsloader.tagLoad=function(path,name){this.jsRunSequence.push({name:name,code:"",path:path,status:"failed"});this.runjs()};lsloader.jsfallback=function(path,name){if(!!this.jsnamemap[name]){return}else{this.jsnamemap[name]=name}for(var k in this.jsRunSequence){if(this.jsRunSequence[k].name==name){this.jsRunSequence[k].code="";this.jsRunSequence[k].status="failed";this.jsRunSequence[k].path=path}}this.runjs()};lsloader.cssfallback=function(path,name,cssonload){if(!!this.cssnamemap[name]){return}else{this.cssnamemap[name]=1}var link=document.createElement("link");link.type="text/css";link.href=path;link.rel="stylesheet";link.onload=link.onerror=cssonload;var root=document.getElementsByTagName("script")[0];root.parentNode.insertBefore(link,root)};lsloader.runInlineScript=function(scriptId,codeId){var code=document.getElementById(codeId).innerText;this.jsRunSequence.push({name:scriptId,code:code});this.runjs()};lsloader.loadCombo=function(jslist){var updateList="";var requestingModules={};for(var k in jslist){var LS=this.getLS(jslist[k].name);if(!!LS){var version=LS.split(versionString)[0];var code=LS.split(versionString)[1]}else{var version=""}if(version==jslist[k].path){this.jsRunSequence.push({name:jslist[k].name,code:code,path:jslist[k].path})}else{this.jsRunSequence.push({name:jslist[k].name,code:null,path:jslist[k].path,status:"comboloading"});requestingModules[jslist[k].name]=true;updateList+=(updateList==""?"":";")+jslist[k].path}}var that=this;if(!!updateList){var xhr=new XMLHttpRequest;xhr.open("get",combo+updateList,true);xhr.onreadystatechange=function(){if(xhr.readyState==4){if(xhr.status>=200&&xhr.status<300||xhr.status==304){if(xhr.response!=""){that.runCombo(xhr.response,requestingModules);return}}else{for(var i in that.jsRunSequence){if(requestingModules[that.jsRunSequence[i].name]){that.jsRunSequence[i].status="failed"}}that.runjs()}}};xhr.send(null)}this.runjs()};lsloader.runCombo=function(comboCode,requestingModules){comboCode=comboCode.split("/*combojs*/");comboCode.shift();for(var k in this.jsRunSequence){if(!!requestingModules[this.jsRunSequence[k].name]&&!!comboCode[0]){this.jsRunSequence[k].status="comboJS";this.jsRunSequence[k].code=comboCode[0];this.setLS(this.jsRunSequence[k].name,this.jsRunSequence[k].path+versionString+comboCode[0]);comboCode.shift()}}this.runjs()}})();</script>

    <!-- Import CSS & jQuery -->
    
        <style id="css/material.min.css"></style><script>if(typeof window.lsLoadCSSMaxNums === "undefined")window.lsLoadCSSMaxNums = 0;window.lsLoadCSSMaxNums++;lsloader.load("css/material.min.css","/blog/css/material.min.css?fJTiM/K1J3dWIruo3pxtAw==",function(){if(typeof window.lsLoadCSSNums === "undefined")window.lsLoadCSSNums = 0;window.lsLoadCSSNums++;if(window.lsLoadCSSNums == window.lsLoadCSSMaxNums)document.documentElement.style.display="";})</script>
        <style id="css/style.min.css"></style><script>if(typeof window.lsLoadCSSMaxNums === "undefined")window.lsLoadCSSMaxNums = 0;window.lsLoadCSSMaxNums++;lsloader.load("css/style.min.css","/blog/css/style.min.css?oCSEO3ST+aEypEwttTDI9g==",function(){if(typeof window.lsLoadCSSNums === "undefined")window.lsLoadCSSNums = 0;window.lsLoadCSSNums++;if(window.lsLoadCSSNums == window.lsLoadCSSMaxNums)document.documentElement.style.display="";})</script>
        
        
            <style>
    
    .footer-sns-facebook {
        background-image: url();
    }
    
    
    .footer-sns-twitter {
        background-image: url();
    }
    
    
    .footer-sns-gplus {
        background-image: url();
    }
    
    
    
    
    
    
    
    
    
</style>

        
        <!-- Config CSS -->

<!-- Other Styles -->
<style>
  body, html {
    font-family: Roboto, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
  }

  a {
    color: #00838F;
  }

  .mdl-card__media,
  #search-label,
  #search-form-label:after,
  #scheme-Paradox .hot_tags-count,
  #scheme-Paradox .sidebar_archives-count,
  #scheme-Paradox .sidebar-colored .sidebar-header,
  #scheme-Paradox .sidebar-colored .sidebar-badge{
    background-color: #0097A7 !important;
  }

  /* Sidebar User Drop Down Menu Text Color */
  #scheme-Paradox .sidebar-colored .sidebar-nav>.dropdown>.dropdown-menu>li>a:hover,
  #scheme-Paradox .sidebar-colored .sidebar-nav>.dropdown>.dropdown-menu>li>a:focus {
    color: #0097A7 !important;
  }

  #post_entry-right-info,
  .sidebar-colored .sidebar-nav li:hover > a,
  .sidebar-colored .sidebar-nav li:hover > a i,
  .sidebar-colored .sidebar-nav li > a:hover,
  .sidebar-colored .sidebar-nav li > a:hover i,
  .sidebar-colored .sidebar-nav li > a:focus i,
  .sidebar-colored .sidebar-nav > .open > a,
  .sidebar-colored .sidebar-nav > .open > a:hover,
  .sidebar-colored .sidebar-nav > .open > a:focus,
  #ds-reset #ds-ctx .ds-ctx-entry .ds-ctx-head a {
    color: #0097A7 !important;
  }

  .toTop {
    background: #757575 !important;
  }

  .material-layout .material-post>.material-nav,
  .material-layout .material-index>.material-nav,
  .material-nav a {
    color: #757575;
  }

  #scheme-Paradox .MD-burger-layer {
    background-color: #757575;
  }

  #scheme-Paradox #post-toc-trigger-btn {
    color: #757575;
  }

  .post-toc a:hover {
    color: #00838F;
    text-decoration: underline;
  }

</style>


<!-- Theme Background Related-->

    <style>
      body{
        background-color: #F5F5F5;
      }

      /* blog_info bottom background */
      #scheme-Paradox .material-layout .something-else .mdl-card__supporting-text{
        background-color: #fff;
      }
    </style>




<!-- Fade Effect -->

    <style>
      .fade {
        transition: all 800ms linear;
        -webkit-transform: translate3d(0,0,0);
        -moz-transform: translate3d(0,0,0);
        -ms-transform: translate3d(0,0,0);
        -o-transform: translate3d(0,0,0);
        transform: translate3d(0,0,0);
        opacity: 1;
      }

      .fade.out{
        opacity: 0;
      }
    </style>


<!-- Import Font -->

    <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons"rel="stylesheet">


        <script>lsloader.load("js/jquery.min.js","/blog/js/jquery.min.js?qcusAULNeBksqffqUM2+Ig==")</script>
    
    
    <script>function Queue(){this.dataStore=[];this.offer=b;this.poll=d;this.execNext=a;this.debug=false;this.startDebug=c;function b(e){if(this.debug){console.log("Offered a Queued Function.")}if(typeof e==="function"){this.dataStore.push(e)}else{console.log("You must offer a function.")}}function d(){if(this.debug){console.log("Polled a Queued Function.")}return this.dataStore.shift()}function a(){var e=this.poll();if(e!==undefined){if(this.debug){console.log("Run a Queued Function.")}e()}}function c(){this.debug=true}}var queue=new Queue();</script>

    <!-- Analytics -->
    

    <!-- Custom Head -->
    
</head>


    
        <body id="scheme-Paradox" class="lazy">
            <div class="material-layout  mdl-js-layout has-drawer is-upgraded">
                

                <!-- Main Container -->
                <main class="material-layout__content" id="main">

                    <!-- Top Anchor -->
                    <div id="top"></div>

                    
                        <!-- Hamburger Button -->
                        <button class="MD-burger-icon sidebar-toggle">
                            <span class="MD-burger-layer"></span>
                        </button>
                    

                    <!-- Post TOC -->

    
    <!-- Back Button -->
    <!--
    <div class="material-back" id="backhome-div" tabindex="0">
        <a class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon"
           href="#" onclick="window.history.back();return false;"
           target="_self"
           role="button"
           data-upgraded=",MaterialButton,MaterialRipple">
            <i class="material-icons" role="presentation">arrow_back</i>
            <span class="mdl-button__ripple-container">
                <span class="mdl-ripple"></span>
            </span>
        </a>
    </div>
    -->

    <!-- Left aligned menu below button -->
    <button id="post-toc-trigger-btn"
        class="mdl-button mdl-js-button mdl-button--icon">
        <i class="material-icons">format_list_numbered</i>
    </button>

    
    <ul class="post-toc-wrap mdl-menu mdl-menu--bottom-left mdl-js-menu mdl-js-ripple-effect" for="post-toc-trigger-btn" style="max-height:80vh; overflow-y:scroll;">
        <ol class="post-toc"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#ECS-专有网络-开启防火墙"><span class="post-toc-number">1.</span> <span class="post-toc-text">ECS 专有网络 开启防火墙</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#安装配置-git"><span class="post-toc-number">2.</span> <span class="post-toc-text">安装配置 git</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#安装配置-nginx"><span class="post-toc-number">3.</span> <span class="post-toc-text">安装配置 nginx</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#安装配置-supervisor"><span class="post-toc-number">4.</span> <span class="post-toc-text">安装配置 supervisor</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#安装配置-postgresql"><span class="post-toc-number">5.</span> <span class="post-toc-text">安装配置 postgresql</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#安装配置-mysql"><span class="post-toc-number">6.</span> <span class="post-toc-text">安装配置 mysql</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#安装配置-gogs"><span class="post-toc-number">7.</span> <span class="post-toc-text">安装配置 gogs</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#官网"><span class="post-toc-number">7.1.</span> <span class="post-toc-text">官网</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#下载最新版的二进制包"><span class="post-toc-number">7.2.</span> <span class="post-toc-text">下载最新版的二进制包</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#创建postgresql-用户gogs-数据库-gogsdb"><span class="post-toc-number">7.3.</span> <span class="post-toc-text">创建postgresql 用户gogs,数据库 gogsdb</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#新增gitusr用户并切换成gitusr，安装配置"><span class="post-toc-number">7.4.</span> <span class="post-toc-text">新增gitusr用户并切换成gitusr，安装配置</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#supervisor-配置"><span class="post-toc-number">7.5.</span> <span class="post-toc-text">supervisor 配置</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#配制运行参数"><span class="post-toc-number">7.6.</span> <span class="post-toc-text">配制运行参数</span></a></li></ol></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#配置git布暑hook"><span class="post-toc-number">8.</span> <span class="post-toc-text">配置git布暑hook</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#初始化祼仓库"><span class="post-toc-number">8.1.</span> <span class="post-toc-text">初始化祼仓库</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#配置post-receive-hook"><span class="post-toc-number">8.2.</span> <span class="post-toc-text">配置post-receive hook</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#使之可执行"><span class="post-toc-number">8.3.</span> <span class="post-toc-text">使之可执行</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#修改文件属性"><span class="post-toc-number">8.4.</span> <span class="post-toc-text">修改文件属性</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#将本机的公钥添加到信任链里"><span class="post-toc-number">8.5.</span> <span class="post-toc-text">将本机的公钥添加到信任链里</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#在本地仓库与远程布暑仓库映射"><span class="post-toc-number">8.6.</span> <span class="post-toc-text">在本地仓库与远程布暑仓库映射</span></a></li></ol></li></ol>
        <!--
        <li class="mdl-menu__item">
            Some Action
        </li>
        -->
    </ul>
    





<!-- Layouts -->

    <!-- Post Module -->
    <div class="material-post_container">

        <div class="material-post mdl-grid">
            <div class="mdl-card mdl-shadow--4dp mdl-cell mdl-cell--12-col">

                <!-- Post Header(Thumbnail & Title) -->
                
    <!-- Paradox Post Header -->
    
        
            <!-- Random Thumbnail -->
            <div class="post_thumbnail-random mdl-card__media mdl-color-text--grey-50">
            <script type="text/ls-javascript" id="post-thumbnail-script">
    var randomNum = Math.floor(Math.random() * 19 + 1);

    $('.post_thumbnail-random').attr('data-original', '/blog/img/random/material-' + randomNum + '.png');
    $('.post_thumbnail-random').addClass('lazy');
</script>

        
    
            <p class="article-headline-p">
                Ubuntu 服务器的安装配置
            </p>
        </div>





                
                    <!-- Paradox Post Info -->
                    <div class="mdl-color-text--grey-700 mdl-card__supporting-text meta">

    <!-- Author Avatar -->
    <div id="author-avatar">
        <img src="/blog/img/avatar.png" width="44px" height="44px" alt="Author Avatar"/>
    </div>
    <!-- Author Name & Date -->
    <div>
        <strong>David</strong>
        <span>8月 18, 2017</span>
    </div>

    <div class="section-spacer"></div>

    <!-- Favorite -->
    <!--
        <button id="article-functions-like-button" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon btn-like">
            <i class="material-icons" role="presentation">favorite</i>
            <span class="visuallyhidden">favorites</span>
        </button>
    -->

    <!-- Qrcode -->
    

    <!-- Tags (bookmark) -->
    
    <button id="article-functions-viewtags-button" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon">
        <i class="material-icons" role="presentation">bookmark</i>
        <span class="visuallyhidden">bookmark</span>
    </button>
    <ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="article-functions-viewtags-button">
        <li class="mdl-menu__item">
        
    </ul>
    

    <!-- Share -->
    <button id="article-fuctions-share-button" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon">
    <i class="material-icons" role="presentation">share</i>
    <span class="visuallyhidden">share</span>
</button>
<ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="article-fuctions-share-button">
    

    

    <!-- Share Weibo -->
    
        <a class="post_share-link" href="http://service.weibo.com/share/share.php?appkey=&title=Ubuntu 服务器的安装配置&url=http://yoursite.com/blog/blog/2017/08/18/server-setup/index.html&pic=&searchPic=false&style=simple" target="_blank">
            <li class="mdl-menu__item">
                分享到微博
            </li>
        </a>
    

    <!-- Share Twitter -->
    
        <a class="post_share-link" href="https://twitter.com/intent/tweet?text=Ubuntu 服务器的安装配置&url=http://yoursite.com/blog/blog/2017/08/18/server-setup/index.html&via=David" target="_blank">
            <li class="mdl-menu__item">
                分享到 Twitter
            </li>
        </a>
    

    <!-- Share Facebook -->
    
        <a class="post_share-link" href="https://www.facebook.com/sharer/sharer.php?u=http://yoursite.com/blog/blog/2017/08/18/server-setup/index.html" target="_blank">
            <li class="mdl-menu__item">
                分享到 Facebook
            </li>
        </a>
    

    <!-- Share Google+ -->
    
        <a class="post_share-link" href="https://plus.google.com/share?url=http://yoursite.com/blog/blog/2017/08/18/server-setup/index.html" target="_blank">
            <li class="mdl-menu__item">
                分享到 Google+
            </li>
        </a>
    

    <!-- Share LinkedIn -->
    

    <!-- Share QQ -->
    

    <!-- Share Telegram -->
    
</ul>

</div>

                

                <!-- Post Content -->
                <div id="post-content" class="mdl-color-text--grey-700 mdl-card__supporting-text fade out">
    
        <h3 id="ECS-专有网络-开启防火墙"><a href="#ECS-专有网络-开启防火墙" class="headerlink" title="ECS 专有网络 开启防火墙"></a>ECS 专有网络 开启防火墙</h3><h3 id="安装配置-git"><a href="#安装配置-git" class="headerlink" title="安装配置 git"></a>安装配置 git</h3><pre><code>sudo add-apt-repository ppa:git-core/ppa  
sudo apt update  
sudo apt install git  

生成.ssh key
ssh-keygen -t rsa -C &quot;email&quot;

git config --global user.name &quot;&quot;
git config --global user.email &quot;&quot;
</code></pre><h3 id="安装配置-nginx"><a href="#安装配置-nginx" class="headerlink" title="安装配置 nginx"></a>安装配置 nginx</h3><pre><code>sudo apt install software-properties-common
sudo apt install python-software-properties

sudo apt-add-repository ppa:nginx/development
sudo apt-get update
sudo apt-get install nginx
sudo service nginx start

vi /etc/nginx/conf.d/app.conf
server {
    listen 80;
    server_name app.site;
    location / {
        root /pathtoapp;
        index index.html index.htm;
        proxy_pass http://127.0.0.1:port;
    }
}
nginx -s reload

let&apos;s encrypt 安装配置后会在 conf文件相应位置加入配置信息
</code></pre><h3 id="安装配置-supervisor"><a href="#安装配置-supervisor" class="headerlink" title="安装配置 supervisor"></a>安装配置 supervisor</h3><pre><code>sudo apt install supervisor

vi /etc/supervisor/conf.d/app.conf
[program:app]
directory=/path/
command=/path/app
autostart=true
autorestart=true
startsecs=10
redirect_stderr=true
stdout_logfile=/path/log/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/path/log/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB

supervisorctl reload
</code></pre><h3 id="安装配置-postgresql"><a href="#安装配置-postgresql" class="headerlink" title="安装配置 postgresql"></a>安装配置 postgresql</h3><p> <a href="http://yunhor.oschina.io/blog/2017/08/14/postgresql-install-and-setup/" target="_blank" rel="external">详见postgresql安装笔记</a></p>
<h3 id="安装配置-mysql"><a href="#安装配置-mysql" class="headerlink" title="安装配置 mysql"></a>安装配置 mysql</h3><p>　　sudo apt install mysql-server mysql-client</p>
<p>　　安装过程中会提示设置密码什么的，注意设置了不要忘了，安装完成之后可以使用如下命令来检查是否安装成功：</p>
<p>　　sudo netstat -tap | grep mysql</p>
<p>　　通过上述命令检查之后，如果看到有mysql 的socket处于 listen 状态则表示安装成功。</p>
<p>　　登陆mysql数据库可以通过如下命令：</p>
<p>　　mysql -u root -p </p>
<pre><code>desc 表名;
show columns from 表名;
describe 表名;
show create table 表名;

use information_schema
select * from columns where table_name=&apos;表名&apos;;

show databases;
show tables;

mysqldump -h -u root -p dbname &gt; backup.sql
mysql -u root -p [dbname] &lt; backup.sql
</code></pre><h3 id="安装配置-gogs"><a href="#安装配置-gogs" class="headerlink" title="安装配置 gogs"></a>安装配置 gogs</h3><h4 id="官网"><a href="#官网" class="headerlink" title="官网"></a><a href="https://gogs.io/" target="_blank" rel="external">官网</a></h4><h4 id="下载最新版的二进制包"><a href="#下载最新版的二进制包" class="headerlink" title="下载最新版的二进制包"></a><a href="https://dl.gogs.io/0.11.29/linux_amd64.tar.gz" target="_blank" rel="external">下载最新版的二进制包</a></h4><h4 id="创建postgresql-用户gogs-数据库-gogsdb"><a href="#创建postgresql-用户gogs-数据库-gogsdb" class="headerlink" title="创建postgresql 用户gogs,数据库 gogsdb"></a>创建postgresql 用户gogs,数据库 gogsdb</h4><pre><code>sudo su - postgres
psql
CREATE USER gogs WITH PASSWORD &apos;password&apos;;
CREATE DATABASE gogsdb OWNER gogs;
\c gogsdb
CREATE EXTENSION pgcrypto; 
SELECT gen_random_uuid();
GRANT ALL PRIVILEGES ON DATABASE gogsdb to gogs;
\q
exit
psql -h 127.0.0.1 -U gogs -d gogsdb

gogs 安装手记 2017-07-25

1. psql 安装配置开户建库

    CREATE USER gogs WITH PASSWORD &apos;amoi66688*&apos;;
    CREATE DATABASE gogs OWNER gogs;
    \c gogs
    CREATE EXTENSION pgcrypto;
    SELECT gen_random_uuid()
    GRANT ALL PRIVILEGES ON DATABASE gogs to gogs;

1. gogs 下载安装配置

    sudo adduser gitusr  pwd amoi66*88*
    su gitusr
    cd ~
    mkdir .ssh 不要到 git 用户的主目录中创建 .ssh 文件夹 gogs会自动创建

    sudo chown gitusr.gitusr -R /home/www/gogs
    sudo chown gitusr.gitusr -R /home/www/gogsrepos
    域名 repos.yunhor.com  port 6666

运行系统用户非当前用户：gitusr -&gt; root
    Gogs-yunhor
    /home/www/gogsrepos
    repos.yunhor.com
    http://repos.yunhor.com/

https://gitter.im/gogits/gogs
</code></pre><h4 id="新增gitusr用户并切换成gitusr，安装配置"><a href="#新增gitusr用户并切换成gitusr，安装配置" class="headerlink" title="新增gitusr用户并切换成gitusr，安装配置"></a>新增gitusr用户并切换成gitusr，安装配置</h4><pre><code>useradd gitusr
passwd gitusr
wget https://dl.gogs.io/0.11.29/linux_amd64.tar.gz
tar zvxf linux_amd64.tar.gz 
mv linux_amd64 gogs
chown -R gitusr.gitusr gogs
sudo su - gitusr

cd gogs
mkdir log
./gogs web -port port
之后按照网页安装
此处port,nginx.conf
</code></pre><h4 id="supervisor-配置"><a href="#supervisor-配置" class="headerlink" title="supervisor 配置"></a>supervisor 配置</h4><pre><code>[program:gogs]
directory=/www/gogs
command=/www/gogs/gogs web
autostart=true
autorestart=true
startsecs=10
redirect_stderr=true
stdout_logfile=/www/gogs/log/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/www/gogs/log/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
user = gitusr
environment = HOME=&quot;/home/gitusr&quot;, USER=&quot;gitusr&quot;
</code></pre><h4 id="配制运行参数"><a href="#配制运行参数" class="headerlink" title="配制运行参数"></a>配制运行参数</h4><pre><code>custom/conf/app.ini
DISABLE_REGISTRATION    //关闭注册按钮    
</code></pre><h3 id="配置git布暑hook"><a href="#配置git布暑hook" class="headerlink" title="配置git布暑hook"></a>配置git布暑hook</h3><h4 id="初始化祼仓库"><a href="#初始化祼仓库" class="headerlink" title="初始化祼仓库"></a>初始化祼仓库</h4><pre><code>cd /pathtoapp/
git init --bare api.git
</code></pre><h4 id="配置post-receive-hook"><a href="#配置post-receive-hook" class="headerlink" title="配置post-receive hook"></a>配置post-receive hook</h4><pre><code>cd api.git/hooks
vi post-receive

#!/bin/sh
GIT_WORK_TREE=/www/weapi/api git checkout -f

supervisorctl restart weapi
</code></pre><h4 id="使之可执行"><a href="#使之可执行" class="headerlink" title="使之可执行"></a>使之可执行</h4><pre><code>chmod +x post-receive
</code></pre><h4 id="修改文件属性"><a href="#修改文件属性" class="headerlink" title="修改文件属性"></a>修改文件属性</h4><pre><code>chown -R gitusr.gitusr /pathtoapp/
</code></pre><h4 id="将本机的公钥添加到信任链里"><a href="#将本机的公钥添加到信任链里" class="headerlink" title="将本机的公钥添加到信任链里"></a>将本机的公钥添加到信任链里</h4><pre><code>$HOME/.ssh/authorized_keys 
__注意:__ 该文件的权限问题，不能让所有者之外的用户对authorized_keys文件有写权限，否则，sshd将不允许使用该文件，因为它可能会被其他用户篡改。
</code></pre><h4 id="在本地仓库与远程布暑仓库映射"><a href="#在本地仓库与远程布暑仓库映射" class="headerlink" title="在本地仓库与远程布暑仓库映射"></a>在本地仓库与远程布暑仓库映射</h4><pre><code>git remote add prod gitusr@host:/pathtogit
</code></pre>
    

    
</div>


                

                <!-- Post Comments -->
                
                    
                
            </div>

            <!-- Post Prev & Next Nav -->
            <nav class="material-nav mdl-color-text--grey-50 mdl-cell mdl-cell--12-col">
    <!-- Prev Nav -->
    
        <a href="/blog/2017/08/21/linux-note/" id="post_nav-newer" class="prev-content">
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation">
                <i class="material-icons">arrow_back</i>
            </button>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            新篇
        </a>
    

    <!-- Section Spacer -->
    <div class="section-spacer"></div>

    <!-- Next Nav -->
    
        <a href="/blog/2017/08/14/postgresql-install-and-setup/" id="post_nav-older" class="next-content">
            旧篇
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation">
                <i class="material-icons">arrow_forward</i>
            </button>
        </a>
    
</nav>

        </div>
    </div>



                    
                        <!-- Overlay For Active Sidebar -->
<div class="sidebar-overlay"></div>

<!-- Material sidebar -->
<aside id="sidebar" class="sidebar sidebar-colored sidebar-fixed-left" role="navigation">
    <div id="sidebar-main">
        <!-- Sidebar Header -->
        <div class="sidebar-header header-cover" style="background-image: url(/blog/img/sidebar_header.png);">
    <!-- Top bar -->
    <div class="top-bar"></div>

    <!-- Sidebar toggle button -->
    <button type="button" class="sidebar-toggle mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon" style="display: initial;" data-upgraded=",MaterialButton,MaterialRipple">
        <i class="material-icons">clear_all</i>
        <span class="mdl-button__ripple-container">
            <span class="mdl-ripple">
            </span>
        </span>
    </button>

    <!-- Sidebar Avatar -->
    <div class="sidebar-image">
        <img src="/blog/img/avatar.png" alt="David's avatar">
    </div>

    <!-- Sidebar Email -->
    <a data-toggle="dropdown" class="sidebar-brand" href="#settings-dropdown">
        youremail@email.com
        <b class="caret"></b>
    </a>
</div>


        <!-- Sidebar Navigation  -->
        <ul class="nav sidebar-nav">
    <!-- User dropdown  -->
    <li class="dropdown">
        <ul id="settings-dropdown" class="dropdown-menu">
            
                <li>
                    <a href="#" target="_blank" title="Email Me">
                        
                            <i class="material-icons sidebar-material-icons sidebar-indent-left1pc-element">email</i>
                        
                        Email Me
                    </a>
                </li>
            
        </ul>
    </li>

    <!-- Homepage -->
    
        <li id="sidebar-first-li">
            <a href="/blog/">
                
                    <i class="material-icons sidebar-material-icons">home</i>
                
                主页
            </a>
        </li>
        
    

    <!-- Archives  -->
    
        <li class="dropdown">
            <a href="#" class="ripple-effect dropdown-toggle" data-toggle="dropdown">
                
                    <i class="material-icons sidebar-material-icons">inbox</i>
                
                    归档
                <b class="caret"></b>
            </a>
            <ul class="dropdown-menu">
            <li>
                <a class="sidebar_archives-link" href="/blog/archives/2018/06/">六月 2018<span class="sidebar_archives-count">2</span></a></li><li><a class="sidebar_archives-link" href="/blog/archives/2018/05/">五月 2018<span class="sidebar_archives-count">3</span></a></li><li><a class="sidebar_archives-link" href="/blog/archives/2018/04/">四月 2018<span class="sidebar_archives-count">1</span></a></li><li><a class="sidebar_archives-link" href="/blog/archives/2018/03/">三月 2018<span class="sidebar_archives-count">4</span></a></li><li><a class="sidebar_archives-link" href="/blog/archives/2018/02/">二月 2018<span class="sidebar_archives-count">4</span></a></li><li><a class="sidebar_archives-link" href="/blog/archives/2017/09/">九月 2017<span class="sidebar_archives-count">2</span></a></li><li><a class="sidebar_archives-link" href="/blog/archives/2017/08/">八月 2017<span class="sidebar_archives-count">8</span></a>
            </ul>
        </li>
        
    

    <!-- Categories  -->
    

    <!-- Pages  -->
    

    <!-- Article Number  -->
    
</ul>


        <!-- Sidebar Footer -->
        <!--
I'm glad you use this theme, the development is no so easy, I hope you can keep the copyright, I will thank you so much.
If you still want to delete the copyrights, could you still retain the first one? Which namely "Theme Material"
It will not impact the appearance and can give developers a lot of support :)

很高兴您使用并喜欢该主题，开发不易 十分谢谢与希望您可以保留一下版权声明。
如果您仍然想删除的话 能否只保留第一项呢？即 "Theme Material"
它不会影响美观并可以给开发者很大的支持和动力。 :)
-->

<!-- Sidebar Divider -->

    <div class="sidebar-divider"></div>


<!-- Theme Material -->

    <a href="https://github.com/viosey/hexo-theme-material"  class="sidebar-footer-text-a" target="_blank">
        <div class="sidebar-text mdl-button mdl-js-button mdl-js-ripple-effect sidebar-footer-text-div" data-upgraded=",MaterialButton,MaterialRipple">
            主题 - Material
            <span class="sidebar-badge badge-circle">i</span>
        </div>
    </a>


<!-- Help & Support -->
<!--

-->

<!-- Feedback -->
<!--

-->

<!-- About Theme -->
<!--

-->

    </div>

    <!-- Sidebar Image -->
    

</aside>

                    

                    
                        <!-- Footer Top Button -->
                        <div id="back-to-top" class="toTop-wrap">
    <a href="#top" class="toTop">
        <i class="material-icons footer_top-i">expand_less</i>
    </a>
</div>

                    

                    <!--Footer-->
<footer class="mdl-mini-footer" id="bottom">
    
        <!-- Paradox Footer Left Section -->
        <div class="mdl-mini-footer--left-section sns-list">
    <!-- Twitter -->
    
        <a href="https://twitter.com/twitter" target="_blank">
            <button class="mdl-mini-footer--social-btn social-btn footer-sns-twitter">
                <span class="visuallyhidden">Twitter</span>
            </button><!--
     --></a>
    

    <!-- Facebook -->
    
        <a href="https://www.facebook.com/facebook" target="_blank">
            <button class="mdl-mini-footer--social-btn social-btn footer-sns-facebook">
                <span class="visuallyhidden">Facebook</span>
            </button><!--
     --></a>
    

    <!-- Google + -->
    
        <a href="https://www.google.com/" target="_blank">
            <button class="mdl-mini-footer--social-btn social-btn footer-sns-gplus">
                <span class="visuallyhidden">Google Plus</span>
            </button><!--
     --></a>
    

    <!-- Weibo -->
    

    <!-- Instagram -->
    

    <!-- Tumblr -->
    

    <!-- Github -->
    

    <!-- LinkedIn -->
    

    <!-- Zhihu -->
    

    <!-- Bilibili -->
    

    <!-- Telegram -->
    
</div>


        <!--Copyright-->
        <div id="copyright">
            Copyright&nbsp;©<script type="text/javascript">var fd = new Date();document.write("&nbsp;" + fd.getFullYear() + "&nbsp;");</script>David's blog
        </div>

        <!-- Paradox Footer Right Section -->

        <!--
        I am glad you use this theme, the development is no so easy, I hope you can keep the copyright.
        It will not impact the appearance and can give developers a lot of support :)

        很高兴您使用该主题，开发不易，希望您可以保留一下版权声明。
        它不会影响美观并可以给开发者很大的支持。 :)
        -->

        <div class="mdl-mini-footer--right-section">
            <div>
                <div class="footer-develop-div">Powered by <a href="https://hexo.io" target="_blank" class="footer-develop-a">Hexo</a></div>
                <div class="footer-develop-div">Theme - <a href="https://github.com/viosey/hexo-theme-material" target="_blank" class="footer-develop-a">Material</a></div>
            </div>
        </div>
    
</footer>


                    <!-- Import File -->


    <script>lsloader.load("js/lazyload.min.js","/blog/js/lazyload.min.js?1BcfzuNXqV+ntF6gq+5X3Q==")</script>
    <script>lsloader.load("js/js.min.js","/blog/js/js.min.js?oAl/+lvaqTFV31JXTmbrNA==")</script>



    <script>lsloader.load("js/nprogress.js","/blog/js/nprogress.js?pl3Qhb9lvqR1FlyLUna1Yw==")</script>


<script type="text/ls-javascript" id="NProgress-script">
    NProgress.configure({
        showSpinner: true
    });
    NProgress.start();
    $('#nprogress .bar').css({
        'background': '#29d'
    });
    $('#nprogress .peg').css({
        'box-shadow': '0 0 10px #29d, 0 0 15px #29d'
    });
    $('#nprogress .spinner-icon').css({
        'border-top-color': '#29d',
        'border-left-color': '#29d'
    });
    setTimeout(function() {
        NProgress.done();
        $('.fade').removeClass('out');
    }, 800);
</script>













<!-- UC Browser Compatible -->
<script>
	var agent = navigator.userAgent.toLowerCase();
	if(agent.indexOf('ucbrowser')>0) {
		document.write('<link rel="stylesheet" href="/blog/css/uc.css">');
	   alert('由于 UC 浏览器使用极旧的内核，而本网站使用了一些新的特性。\n为了您能更好的浏览，推荐使用 Chrome 或 Firefox 浏览器。');
	}
</script>

<!-- Window Load-->
<script type="text/ls-javascript" id="window-load">
    $(window).on('load', function() {
        // Post_Toc parent position fixed
        $('.post-toc-wrap').parent('.mdl-menu__container').css('position', 'fixed');
    });
</script>

<!-- MathJax Load-->

<script type="text/ls-javascript" id="lazy-load">
    // Offer LazyLoad
    queue.offer(function(){
        $('.lazy').lazyload({
            effect : 'show'
        });
    });

    // Start Queue
    $(document).ready(function(){
        setInterval(function(){
            queue.execNext();
        },200);
    });
</script>

<!-- Bing Background -->


<script>
    (function(){
        var scriptList = document.querySelectorAll('script[type="text/ls-javascript"]')

        for (var i = 0; i < scriptList.length; ++i) {
            var item = scriptList[i];
            lsloader.runInlineScript(item.id,item.id);
        }
    })()
console.log('\n %c © Material Theme | Version: 1.4.0 | https://github.com/viosey/hexo-theme-material %c \n', 'color:#455a64;background:#e0e0e0;padding:5px 0;border-top-left-radius:5px;border-bottom-left-radius:5px;', 'color:#455a64;background:#e0e0e0;padding:5px 0;border-top-right-radius:5px;border-bottom-right-radius:5px;');
</script>

                </main>
            </div>
        </body>
    
</html>
